package com.sk.waste.app.activitys

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.RequiresApi
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.lc.smc.lib.annotations.LCBindView
import com.lc.smc.lib.utils.LCBaseUtil
import com.sk.waste.app.R
import com.sk.waste.app.application.MyApplication
import com.sk.waste.app.bases.BaseActiivity
import com.sk.waste.app.config.NetWorkConfig
import com.sk.waste.app.models.MerchantlModel
import com.sk.waste.app.utils.BaseUtil

/**
 *  @time 2025/4/25  17:11
 *  @desc 商户详情
 */
class ShDetailActivity : BaseActiivity() {


    @LCBindView(R.id.ac_merchant_avatar)
    private lateinit var imgAvatar: ImageView

    @LCBindView(R.id.ac_merchant_name)
    private lateinit var ttvName: TextView

    @LCBindView(R.id.ac_merchant_date)
    private lateinit var ttvDate: TextView

    @LCBindView(R.id.ac_merchant_adress)
    private lateinit var ttvAdress: TextView

    @LCBindView(R.id.ac_merchant_introduction)
    private lateinit var ttvIntroduction: TextView

    @LCBindView(R.id.ac_merchant_business)
    private lateinit var ttvBusiness: TextView

    @LCBindView(R.id.ac_merchant_phone)
    private lateinit var ttvPhone: TextView

    @LCBindView(R.id.ac_merchant_website)
    private lateinit var ttvWebsite: TextView

    private lateinit var merchantlDetail: MerchantlModel
    private val uerinfo = MyApplication.instance.getUserInfo()

    override fun onCreate(savedInstanceState: Bundle?) {
        setContentView(R.layout.activity_merchant_detail)
        super.onCreate(savedInstanceState)
        setBack()
        setTitleView("商户详情")
        setMerchantDetail()
    }

    /**
     *  @time 2025/7/1  11:26
     *  @author Im_jingwei
     *  @desc 设置详情
     */
    private fun setMerchantDetail() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            merchantlDetail = intent.getSerializableExtra("extral_merchant", MerchantlModel::class.java)!!
        } else {
            merchantlDetail = intent.getSerializableExtra("extral_merchant")!! as MerchantlModel
        }

        if (!LCBaseUtil.isNull(merchantlDetail.avatar)) {
            val path = NetWorkConfig.NET_URL_ROOT + NetWorkConfig.NET_URL_USER_AVATAR + merchantlDetail.avatar
            Glide.with(mContext).load(path).transform(CenterCrop(), RoundedCorners(20))
                .error(R.mipmap.img_user_default).into(imgAvatar);
        }
        ttvName.text = merchantlDetail.account
        if (!LCBaseUtil.isNull(merchantlDetail.nickName)) {
            ttvName.text = merchantlDetail.nickName
        }
        ttvDate.text = "入驻日期：" + merchantlDetail.createTime
        ttvAdress.text = "地址：" + merchantlDetail.address

        ttvIntroduction.text = merchantlDetail.companyIntroduction
        ttvBusiness.text = merchantlDetail.mainBusiness
        ttvPhone.text = merchantlDetail.phone
        if (merchantlDetail.companyWebsite.isNotEmpty()) {
            ttvWebsite.text = merchantlDetail.companyWebsite
        }

        if (uerinfo!!.isVip()) {
            ttvPhone.text = merchantlDetail.phone
        } else {
            ttvPhone.text = BaseUtil.getPhoneHideStr(merchantlDetail.phone)
        }
        ttvPhone.setOnClickListener {
            if (uerinfo.isVip()) {
                if (!merchantlDetail.phone.contains(",") && !merchantlDetail.phone.contains("，")) {
                    BaseUtil.callPhone(mContext, merchantlDetail.phone)
                }
            }
        }

        ttvWebsite.setOnClickListener {
            val intent = Intent(mContext, WebViewActivity::class.java)
            intent.putExtra("extral_title", "商户官网")
            intent.putExtra("extral_path", merchantlDetail.companyWebsite)
            startActivity(intent)
        }
    }


}